using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace LogParser.DA
{
    public class UserModel
    {

        public UserModel()
        {

        }

        public static DA.DataObjects.UsersDS.UsersSelectDataTable UsersSelectDataTable()
        {
            DA.DataObjects.UsersDSTableAdapters.UsersSelectTableAdapter ta = TableAdapters.UsersSelectTableAdapter();
            DA.DataObjects.UsersDS.UsersSelectDataTable dt = ta.GetData();

            return dt;
        }


        public static DA.DataObjects.UsersDS.UsersSelectRow UsersSelectDataTable( string login )
        {
            DA.DataObjects.UsersDSTableAdapters.UsersSelectTableAdapter ta = TableAdapters.UsersSelectTableAdapter();
            DA.DataObjects.UsersDS.UsersSelectRow dr = ( (DA.DataObjects.UsersDS.UsersSelectRow) ( (DA.DataObjects.UsersDS.UsersSelectDataTable) ta.UsersSelectByLogin( login ) ).Rows[ 0 ] );

            return dr;
        }

        public static DA.DataObjects.UsersDS.UsersSelectRow UsersSelectDataTableAuthenticate( string login, string password )
        {
            DA.DataObjects.UsersDSTableAdapters.UsersSelectTableAdapter ta = TableAdapters.UsersSelectTableAdapter();
            DA.DataObjects.UsersDS.UsersSelectDataTable dt = (DA.DataObjects.UsersDS.UsersSelectDataTable) ta.UsersSelectByLogin( login );

            if ( dt.Rows.Count > 0 )
            {
                DA.DataObjects.UsersDS.UsersSelectRow dr = ( (DA.DataObjects.UsersDS.UsersSelectRow) dt.Rows[ 0 ] );
                return dr;
            }

            return null;
        }

        public static bool UsersLastLoginUpdate( string login, DateTime loginTime )
        {
            DA.DataObjects.UsersDSTableAdapters.UsersSelectTableAdapter ta = TableAdapters.UsersSelectTableAdapter();

            bool result = false;
            try
            {
                ta.UsersUpdateLastLogin( login, loginTime );
                result = true;
            }
            catch
            {
                result = false;
            }

            return result;

        }

    }
}
